layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var testTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),testTable)
            }
        },
        initTable:function(){
            testTable = table.render({
                elem : '#testTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + 'cms/todo/list.json' // 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },

                {

                    field : 'name', 
                        title : 'name',
                    align: 'center',
                    width:"165"
                },
                {

                    field : 'phone', 
                        title : 'phone',
                    align: 'center',
                    width:"180"
                },

        ] ]

        });

            table.on('checkbox(testTable)', function(obj){
                var test = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },

        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),testTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "cms/todo/add.do";
                    Common.openDlg(url,"Test>新增");
                },
                edit : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"testTable");
                    if(data==null){
                        return ;
                    }
                    var url = "cms/todo/edit.do?id="+data.id;
                    Common.openDlg(url,"Test>编辑");
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del
                        delView.delBatch();
                    });
                }
            ,
                exportDocument : function() {
                    layui.use([ 'testApi' ], function() {
                        var testApi = layui.testApi
                        Common.openConfirm("确认要导出这些Test数据?", function() {
                            testApi.exportExcel($("#searchForm"), function(fileId) {
                                Lib.download(fileId);
                            })
                        })
                    });
                },
                importDocument:function(){
                    var uploadUrl = Common.ctxPath+"cms/todo/excel/import.do";
                    //模板,
                    var templatePath= "cms/todo/test_upload_template.xls";
                    //公共的简单上传文件处理
                    var url = "/core/file/simpleUpload.do?uploadUrl="+uploadUrl+"&templatePath="+templatePath;
                    Common.openDlg(url, "Test>上传");
                }
        };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('index',view);

});